from django.db.models import Count

from notebook.models import Notebook


def get_notebook_count():
    """
    获取笔记本的总数量
    """
    # notebook_num = Notebook.objects.count()  # 通常的方法
    # 使用聚合获取数量
    notebooks = Notebook.objects.aggregate(notebook_numbers=Count("*"))
    # 通过 notebooks.get("notebook_numbers") 获取数量
    # notebooks = Notebook.objects.annotate(notebook_numbers=Count("user"))
    # 通过 notebooks[0].notebook_numbers 获取每篇笔记的作者数量
    return notebooks
